package objectSocket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class LoginClient {

	public static void main(String[] args) {
		try {
			// 创建客户端Socket
			Socket s = new Socket("localhost",4000);
			// 通过输出流发送请求
			OutputStream os = s.getOutputStream();
			ObjectOutputStream oos = new ObjectOutputStream(os);
			User user = new User("yy","yy123456");
			oos.writeObject(user);
			oos.flush();
			s.shutdownOutput();
			// 通过输入流来接收服务器端给客户的响应
			InputStream is = s.getInputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(is));
			String reply;
			while((reply = br.readLine()) != null){
				System.out.println("服务器的响应：" + reply);
			}
			// 释放资源
			br.close();
			is.close();
			oos.close();
			os.close();
			s.close();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
